unit uMensagens;

interface
uses
    Forms, SysUtils, Windows;

Type
    TParamMsg = array of string;

    TDialog = Class

       {$REGION '<< Methods >>'}

         class Function Send( Const Msg : String; Flags : Word = mb_Ok; Const UseDefault : Boolean = True ): Integer; overload;
         class Function Send( Const Msg : String; Params : array of const; Flags : Word = mb_Ok; Const UseDefault : Boolean = True ): Integer; overload;
         class procedure AbortOperation (Msg : String);
         class Function  Agree( Const Msg : String; UseDefaults : Boolean = False) : Boolean;

        {$ENDREGION}

    End;

implementation

uses
  Controls;

{$REGION '<< TGerenteMensagens >>'}

class procedure TDialog.AbortOperation(Msg: String);
begin
  Send (Msg , mb_IconError);
   Abort;
end;

class function TDialog.Agree(const Msg: String;
  UseDefaults: Boolean): Boolean;
begin
   Result :=Send ( Msg, mb_YesNo , UseDefaults) = idYes
end;

class function TDialog.Send(const Msg: String; Flags: Word; const UseDefault: Boolean ): Integer;
Var
   CursorAnt : HCursor;
   Tam : Integer;
Begin
   Tam := Length ( Msg );
   CursorAnt  := Screen.Cursor;
   Try
      Result := 0;
      Screen.Cursor := crDefault;
      If UseDefault And ( ( Flags And $F00 ) = 0 )
         Then Case ( Flags And $0F ) Of
                 mb_OkCancel         : Flags := Flags Or mb_DefButton1;
                 mb_YesNo,
                 mb_RetryCancel,
                 mb_AbortRetryIgnore : Flags := Flags Or mb_DefButton2;
                 mb_YesNoCancel      : Flags := Flags Or mb_DefButton3;
              End;
      If ( Flags And $F0 ) = 0
         Then Case ( Flags And $0F ) Of
                 mb_YesNo,
                 mb_YesNoCancel      : Flags := Flags Or mb_IconQuestion;
                 mb_AbortRetryIgnore : Flags := Flags Or mb_IconHand;
                 mb_Ok               : If ( Tam > 0 ) And ( Msg [ Tam ] = '!' )
                                          Then Flags := Flags Or mb_IconWarning;
              End;
      With Application
        Do Begin
              NormalizeTopMosts;
              Result := MessageBox ( PChar(Msg), PChar(Title), Flags )
           End
   Finally
      Application.RestoreTopMosts;
      Screen.Cursor := CursorAnt
   End
End;

class function TDialog.Send( Const Msg : String; Params : array of const; Flags : Word = mb_Ok; Const UseDefault : Boolean = True ): Integer;
begin
  Result :=Send( Format(Msg, Params), Flags, UseDefault )
end;

{$ENDREGION}

end.

